package nz.co.doherty.gwtpbreadcrumbs.server.handler.product;

import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.product.ProductCreateAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.product.ProductCreateResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class ProductCreateHandler implements
		ActionHandler<ProductCreateAction, ProductCreateResult> {

	
	@Override
	public ProductCreateResult execute(ProductCreateAction action,
			ExecutionContext context) throws ActionException {
		
		Objectify ofy = ObjectifyService.begin();
		return new ProductCreateResult(ofy.put(action
				.getProduct()));
		
	}

	@Override
	public void undo(ProductCreateAction action, ProductCreateResult result,
			ExecutionContext context) throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<ProductCreateAction> getActionType() {		
		return ProductCreateAction.class;
	}

}
